package hhAcademicBowl;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import java.io.File;

import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.WindowConstants;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class DailyDouble {

	private JFrame frame;
	final private Question qToGoTo;
	
	private JTextField wagerVal;

	/**
	 * Create the application.
	 * @param q 
	 */
	public DailyDouble(Question q) {
		qToGoTo = q;
		playSound();
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	void initialize() {
		frame = new JFrame();
		
		frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		
		
		final JFrame fr = frame;
		frame.getContentPane().setBackground(ColorConstants.BG);
		frame.getContentPane().setLayout(null);
		Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
		//Dimension screen = new Dimension(1080,720);
		frame.setBounds(0,0,screen.width,screen.height);
		frame.setUndecorated(true); //maximized
		
		JTextArea txtrDailyDouble = new JTextArea(); 
		txtrDailyDouble.setBackground(ColorConstants.BG);
		txtrDailyDouble.setEditable(false);
		txtrDailyDouble.setLineWrap(true);
		txtrDailyDouble.setWrapStyleWord(true);
		txtrDailyDouble.setText("DAILY DOUBLE");
		txtrDailyDouble.setFont(new Font("Impact", Font.BOLD, 99));
		txtrDailyDouble.setBounds((screen.width-333)/2, (screen.height-250)/2, 333, 251);
		frame.getContentPane().add(txtrDailyDouble);
		
		//CONTROL PANEL------------------------------------------------------------------------------------------
		
		JPanel controlPanel = new JPanel();
		controlPanel.setBorder(null);
		controlPanel.setBackground(ColorConstants.BG);
		int contY = (txtrDailyDouble.getY() + txtrDailyDouble.getHeight() + 10);
		int qWidth = screen.width/2;
		controlPanel.setBounds((screen.width-qWidth)/2, contY, qWidth, ((int) screen.getHeight() - contY - 20));
		frame.getContentPane().add(controlPanel);
		controlPanel.setLayout(null);
		
		JLabel lblWager = new JLabel("Wager");
		lblWager.setHorizontalAlignment(SwingConstants.CENTER);
		lblWager.setFont(new Font("Tahoma", Font.PLAIN, 60));
		lblWager.setBounds(10, 11, 211, 82);
		controlPanel.add(lblWager);
		
		wagerVal = new JTextField();
		wagerVal.setFont(new Font("Tahoma", Font.PLAIN, 60));
		wagerVal.setBounds(10, 133, 211, 46);
		controlPanel.add(wagerVal);
		wagerVal.setColumns(10);
		
		
		JButton btnGoToQuestion = new JButton("Go To Question");
		btnGoToQuestion.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				qToGoTo.Value = Integer.parseInt(wagerVal.getText());
				fr.dispose();
				qToGoTo.frame.setVisible(true);
			}
		});
		btnGoToQuestion.setFont(new Font("Tahoma", Font.PLAIN, 20));
		btnGoToQuestion.setBounds(404, 128, 180, 51);
		controlPanel.add(btnGoToQuestion);
		
		
		
		
		frame.setVisible(true);
		
	}
	
	private void playSound(){
	    try{
	        AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File("jdaily2x.wav").getAbsoluteFile());
	        Clip clip = AudioSystem.getClip();
	        clip.open(audioInputStream);
	        clip.start();
	    }catch(Exception ex){
	        System.out.println("Error with playing sound.");
	        ex.printStackTrace();
	    }
	}
}
